#!/bin/bash
# 从现有128x128图标生成其他尺寸的图标
# 需要安装 ImageMagick: brew install imagemagick 或 sudo apt install imagemagick

set -e

ICON_DIR="/Users/dddpeter/myworks/notepad--/src/linux/usr/share/icons/hicolor"
SOURCE_ICON="$ICON_DIR/128x128/apps/notepad--.png"

if [ ! -f "$SOURCE_ICON" ]; then
    echo "错误：源图标不存在: $SOURCE_ICON"
    exit 1
fi

if ! command -v convert &> /dev/null; then
    echo "错误：需要安装 ImageMagick"
    echo "macOS: brew install imagemagick"
    echo "Linux: sudo apt install imagemagick"
    exit 1
fi

echo "从 128x128 源图标生成其他尺寸..."

# 定义需要的尺寸
SIZES=(16 22 24 48 256 512)

for size in "${SIZES[@]}"; do
    TARGET_DIR="$ICON_DIR/${size}x${size}/apps"
    TARGET_FILE="$TARGET_DIR/notepad--.png"
    
    # 如果文件已存在，跳过
    if [ -f "$TARGET_FILE" ]; then
        echo "✓ 已存在: ${size}x${size}"
        continue
    fi
    
    # 创建目录
    mkdir -p "$TARGET_DIR"
    
    # 生成图标
    convert "$SOURCE_ICON" -resize ${size}x${size} "$TARGET_FILE"
    
    if [ -f "$TARGET_FILE" ]; then
        echo "✓ 已生成: ${size}x${size}"
    else
        echo "✗ 生成失败: ${size}x${size}"
    fi
done

echo ""
echo "图标生成完成！"
echo "生成的图标位于: $ICON_DIR"
echo ""
echo "请将新生成的图标文件提交到git:"
echo "  git add src/linux/usr/share/icons/"
echo "  git commit -m 'Add missing icon sizes for Linux'"

